import { getMainMenu, resetPassword, getNews, getAcademyList } from '@/api/base'
import { type MenuItem, type Menu } from '@/models/menu'
import { type news } from '@/models/news'
import { ObjectParseMenuItem, getLeafNum } from '@/utils/baseUtil'
export async function GetMainMenu(): Promise<Menu> {
  const res = (await getMainMenu()) as any
  const data = res.data
  const menuList: MenuItem[] = []
  ObjectParseMenuItem(data, menuList)
  const menu: Menu = {
    itemList: menuList,
    leafNum: getLeafNum(menuList)
  }
  return menu
}
export async function ResetPassword(prevPas: string, newPas: string): Promise<void> {
  await resetPassword(prevPas, newPas)
}
export async function GetNews(number: number): Promise<news[]> {
  const newsList: news[] = []
  const res = (await getNews(number)) as any
  const news = res.data
  news.forEach((element: Object) => {
    const n: news = element as news
    newsList.push(n)
  })
  return newsList
}
export async function GetAcademyList(): Promise<{ name: string; id: number }[]> {
  const res = (await getAcademyList()) as any
  return res.data
}
